﻿using Microsoft.Extensions.Localization;
using PHMEE.Localization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Domain.Services;
using Volo.Abp.Guids;

namespace PHMEE
{
    public class SysParaManager : DomainService, ISysParaManager
    {
        private readonly IStringLocalizer<PHMEEResource> L;
        private readonly IGuidGenerator _guidGenerator;
        private readonly ISysParaRepository _sysParaRepository;
        private readonly ISysParaExtendRepository _sysParaExtendRepository;

        public SysParaManager(IStringLocalizer<PHMEEResource> L, ISysParaRepository sysParaRepository, ISysParaExtendRepository sysParaExtendRepository, IGuidGenerator guidGenerator)
        {
            this.L = L;
            _sysParaRepository = sysParaRepository;
            _sysParaExtendRepository = sysParaExtendRepository;
            _guidGenerator = guidGenerator;
        }
        public async Task<SysPara> CreateSysPara(string code, int valueSpan)
        {
            var exitCollectCode = await _sysParaRepository.FirstOrDefaultAsync(item => item.CollectorCode == code);
            if (exitCollectCode != null)
            {
                throw new UserFriendlyException("采集器编码已经存在");
            }
            var id = _guidGenerator.Create();

            return new SysPara(id, valueSpan);
        }
    }
}
